home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d11 / nansi22b.arc / SETRAW.MSC < prev    next >
Text File  |  1987-12-03  |  2KB  |  62 lines

  1. /*--- setraw.msc -------------------------------------------------
  2.   Routines to set and reset raw mode on stdin/stdout.
  3.   For Microsoft C.
  4. ------------------------------------------------------------------*/
  5. #include <stdio.h>
  6. #include <dos.h>
  7. /* Use the IOCTL DOS function call to change stdin and stdout to raw mode.
  8.  * For stdin, this prevents MSDOS from trapping ^P, ^S, ^C, thus freeing us
  9.  * of ^P toggling 'echo to printer'.
  10.  * For stdout, this radically speeds up the output because there is no
  11.  * checking for these special characters in the input buffer whenever
  12.  * screen output is occurring.
  13.  * Note that only the stdin OR stdout ioctl need be changed since
  14.  * apparently they are handled as the same device.
  15.  * Thanks to Mark Zbikowski (markz@microsoft.UUCP) for helping me with
  16.  * this.
  17.  * --- This stolen from sources to the mighty game HACK ---
  18.  */
  19. #define DEVICE        0x80
  20. #define RAW        0x20
  21. #define IOCTL        0x44
  22. #define STDIN        fileno(stdin)
  23. #define STDOUT        fileno(stdout)
  24. #define GETBITS     0
  25. #define SETBITS     1
  26. static unsigned old_stdin, old_stdout, ioctl();
  27. /*--- set_raw() ----------
  28.   Call this to set raw mode; call restore_raw() later to restore
  29.   console to old rawness state.
  30. --------------------------*/
  31. set_raw()
  32. {
  33.     old_stdin = ioctl(STDIN, GETBITS, 0);
  34.     old_stdout = ioctl(STDOUT, GETBITS, 0);
  35.     if (old_stdin & DEVICE)
  36.         ioctl(STDIN, SETBITS, old_stdin | RAW);
  37.     if (old_stdout & DEVICE)
  38.         ioctl(STDOUT, SETBITS, old_stdout | RAW);
  39. }
  40. restore_raw()
  41. {
  42.     if (old_stdin)
  43.         (void) ioctl(STDIN, SETBITS, old_stdin);
  44.     if (old_stdout)
  45.         (void) ioctl(STDOUT, SETBITS, old_stdout);
  46. }
  47. static unsigned
  48. ioctl(handle, mode, setvalue)
  49. unsigned setvalue;
  50. {
  51.     union REGS regs;
  52.  
  53.     regs.h.ah = IOCTL;
  54.     regs.h.al = mode;
  55.     regs.x.bx = handle;
  56.     regs.h.dl = setvalue;
  57.     regs.h.dh = 0;            /* Zero out dh */
  58.     intdos(®s, ®s);
  59.     return (regs.x.dx);
  60. }
  61. /*-- end of setraw.msc --*/
  62.